package com.token.iot.bratterycharging.gateway.business;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.outstanding.framework.core.PendingException;
import com.token.iot.bratterycharging.gateway.IDGeneration;
import com.token.iot.bratterycharging.gateway.api.Constant;
import com.token.iot.bratterycharging.gateway.api.Port;
import com.token.iot.bratterycharging.gateway.utils.ByteUtil;

/**
 * 设置充电站充满自停
 * @author chenzhixuan
 *
 */
@Component("CHIDuplexProcessor")
public class CHIDuplexProcessor extends DuplexProcessor {

	@Override
	public String request(String imei, Map<String, String> params) throws PendingException {
		String sessionId = IDGeneration.createSeesionID();
		String command = null;
		String flag = params.get(Constant.FLAG);
		
		String ic = params.get(Constant.CARD);
		command = code + sessionId + "/";
		if("true".equalsIgnoreCase(flag)) {
			command =command+"1";
		}else {
			command=command+"0";
		}
		if("true".equalsIgnoreCase(ic)) {
			command =command+"1";
		}else {
			command=command+"0";
		}
		loger.debug("the send =" + new String(command));
		byte[] cc = ByteUtil.addFlag(command.getBytes());
		context.writeAndFlush(cc);
		return sessionId;

	}

	@Override
	public Boolean response(String response) throws PendingException {
		String val = response.substring(14);
		loger.debug(val);
		return true;

	}

}
